import axios from "axios";

export default {
  state: {
    list: [],
    count: 0,
    dirt: {},
  },
  getters: {},
  mutations: {
    UpdateColectionList(state, info) {
      state.list = info.list;
      for (let badge of info.list) {
        state.dirt[badge.id] = badge;
      }
    },
  },
  actions: {
    getCollections(context) {
      return new Promise((resolve, reject) => {
        axios
          .get(`/api/collections/`)
          .then((response) => {
            context.commit("UpdateColectionList", {
              list: response.data.results,
              count: response.data.count,
            });
            resolve(response);
          })
          .catch((error) => {
            reject(error);
          });
      });
    },
  },
  modules: {},
};
